package com.overlord.im.connector.message.resolver;

import com.overlord.im.commons.constant.AckType;
import com.overlord.im.commons.message.OverlordImMessage;
import com.overlord.im.connector.mq.sender.AckMessageSenderRabbitMqSender;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName MessageAckResolver
 * @Author wuwei
 * @Description 处理消息的ack
 * @Date 2020/6/2 14:00
 **/
@Slf4j
public class MessageAckResolver implements Resolver {

    private AckMessageSenderRabbitMqSender ackMessageSenderRabbitMqSender;


    public MessageAckResolver(AckMessageSenderRabbitMqSender ackMessageSenderRabbitMqSender) {
        this.ackMessageSenderRabbitMqSender = ackMessageSenderRabbitMqSender;
    }

    @Override
    public boolean support(OverlordImMessage message) {
        return message.getAckType() != AckType.NONE;
    }

    @Override
    public void resolve(OverlordImMessage message, ChannelHandlerContext ctx) {
        log.info("ack消息:{}", message);
        ackMessageSenderRabbitMqSender.send(message);
    }
}
